<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  mounted() {
    // 调用方法加载违禁词
    this.loadInitialForbiddenWords();
  },
  methods: {
    async loadInitialForbiddenWords() {
      try {
        const res = await fetch('http://localhost:8888/api/forbidden-words');

        if (!res.ok) {
          throw new Error(`HTTP error! status: ${res.status}`);
        }

        const data = await res.json();

        // 更新 Vuex store 中的敏感词列表
        this.$store.dispatch('updateForbiddenWords', data.map(w => w.word));
      } catch (e) {
        console.error("加载违禁词失败:", e);
        this.$message.warning('无法加载敏感词，请检查后端服务是否运行');
      }
    }
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 10px;
}
</style>